/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controllers;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.Query;
import rede.Foto;

/**
 *
 * @author Alysson
 */
public class FotoController {
 
      EntityManager em = Persistence.createEntityManagerFactory("EasyAcceptPU").createEntityManager();
    
    public void cadastrarUsuario(Foto foto){
        em.getTransaction().begin();
        em.merge(foto);
        em.getTransaction().commit();
    }
    
      //Listando Todas as Fotos Cadastrados No Banco.
    public List<Foto> listarFotos(){
        Query query = this.em.createQuery("SELECT f FROM Foto f");
        return query.getResultList();
    }
    
    //Removendo Foto
     public void removerFoto(Foto foto){
        em.getTransaction().begin();
        em.remove(foto);
        em.getTransaction().commit();
    }
}
